<extend name="Base:main" />
<block name="script">
  <link rel="stylesheet" href="__PUBLIC__/seller/css/validform.css" />
  <script src="__PUBLIC__/seller/js/Validform_v5.3.2.js"></script>
</block>
<block name="content">
<div class="tpl-content-wrapper">
  <div class="tpl-content-page-title"> 订单列表 </div>
  <ol class="am-breadcrumb">
    <li><a href="#" class="am-icon-home">首页</a></li>
    <li><a href="#">订单管理</a></li>
    <li class="am-active">
      订单列表
    </li>
  </ol>
  <div class="tpl-portlet-components">
    <ul class="am-tabs-nav am-nav am-nav-tabs">
      <li 
      <eq name="Think.get.status" value="2">class="am-active"</eq>
      <empty name="Think.get.status" >class="am-active"</empty>
      ><a href="{:U('Order/distributionList')}">已确认订单 ({$order_total})</a>
      </li>
      <li 
      <eq name="Think.get.status" value="1">class="am-active"</eq>
      ><a href="{:U('Order/distributionList',array('status' => 1))}">未确认订单 ({$draft_order_total})</a>
      </li>
      <li 
      <eq name="Think.get.status" value="3">class="am-active"</eq>
      ><a href="{:U('Order/distributionList',array('status' => 3))}">失效订单 ({$invalid_order_total})</a>
      </li>
    </ul>
    <div class="tpl-block">
      <div class="am-g">
        <form class="am-form" action="{:U('Goods/index')}" method="get">
          <input type="hidden" name="c" value="{$Think.const.CONTROLLER_NAME}" class="form-control">
          <input type="hidden" name="a" value="{$Think.const.ACTION_NAME}" class="form-control">
          <input type="hidden" name="m" value="{$Think.const.MODULE_NAME}" class="form-control">
          <div class="am-u-sm-12 am-u-md-5">
            <label class=" am-form-label">订单编号</label>
            <span style="display: inline-block;">
            <input type="text"  name="keyword" value="{$sh.keyword}"  class=" am-form-field">
            </span>
            <label class=" am-form-label">&nbsp;&nbsp;&nbsp;订购人</label>
            <span style="display: inline-block;">
            <input type="text" name="sku" value="{$sh.sku}" class=" am-form-field">
            </span> </div>
          <div class="am-u-sm-12 am-u-md-3">
            <div class="am-input-group am-input-group-sm">
              <button type="submit" class="btn btn-purple btn-sm"> <span class="ace-icon fa fa-search icon-on-right bigger-110"></span> Search </button>
            </div>
          </div>
        </form>
      </div>
      <div class="am-g">
        <div class="am-u-sm-12">
          <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
              <tr>
                <th class="center"><input class="check-all" type="checkbox" value=""></th>
                <th>订单编号</th>
                <th>来源平台</th>
                <th>贸易模式</th>
                <th>购买人</th>
                <th>运费</th>
                <th>优惠金额</th>
                <th>订单总额</th>
                <th>支付状态</th>
                <th>发货状态</th>
                <th>创建时间</th>
                <th class="table-set">操作</th>
              </tr>
            </thead>
            <tbody>
              <volist name="data['list']" id="val">
                <tr>
                  <td class="center"><input class="ids" type="checkbox" name="ids[]" value="{$val['id']}"></td>
                  <td><a href="{:U('detail',array('ref'=>$val['ref']))}">{$val['ref']}</a></td>
                  <td><empty name="val.platform_name"> 平台下单
                      <else />
                      {$val.platform_name} </empty></td>
                  <td>{$val['trade_pattern']}</td>
                  <td>{$val['buyer_name']}</td>
                  <td>{$val['delivery_fee']}</td>
                  <td>{$val['discount']}</td>
                  <td>{$val['amount_total']}</td>
				  <td>
					<switch name="val.pay_status">
						<case value="0">未支付</case>
						<case value="1">支付一部分</case>
						<case value="2">全部支付</case>
					</switch>
				  </td>
                  <td>
					<switch name="val.express_send_status">
						<case value="0">未发货</case>
						<case value="1">发货一部分</case>
						<case value="2">全部发货</case>
					</switch>
				  </td>
                  <td>{$val['create_time']}</td>
                  <td><div class="am-btn-toolbar">
                      <div class="am-btn-group am-btn-group-xs">
                        <button class="am-btn am-btn-default am-btn-xs am-text-secondary">
                        <span class="am-icon-pencil-square-o"></span> <a href="{:U('detail',array('ref'=>$val['ref']))}">订单详情</a>
                        </button>
                        <eq name="val.status" value="2">
                        <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" menu="tip_menu" href="{:U('Order/delete' , array('id' => $value['id']))}" request_type="ajax" title="确定要删除此订单？"><span class="am-icon-trash-o"></span> 删除</button>
                        <else />
                        <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" menu="tip_menu" href="{:U('Order/cancel' , array('id' => $value['id']))}" request_type="ajax" title="确定要取消此订单？"><span class="am-icon-trash-o"></span> 取消订单</button>
                        </eq>
                      </div>
                    </div></td>
                </tr>
              </volist>
            </tbody>
          </table>
          <div class="am-cf">
            <div class="am-fr">
              <ul class="am-pagination tpl-pagination">
                {$data['page']}
              </ul>
            </div>
          </div>
          <hr>
          <eq name="status" value="0">
          <div class="am-btn-group">
            <button type="button" class="am-btn am-btn-primary am-radius check_ok" data-type="ok"><span class="am-icon-check"></span> 批量确认</button>
            <button type="button" class="am-btn am-btn-primary am-radius check_ok" data-type="cencal"><span class="am-icon-trash-o"></span> 批量取消</button>
          </div>
          </eq>
        </div>
      </div>
    </div>
    <div class="tpl-alert"></div>
  </div>
</div>
<script>
	$(function () {
		var goods_type_id = $('#goods_type').val();
		if(goods_type_id){
			$('#goods_type_id option').each(function(){
				if( goods_type_id == $(this).attr('value') ) {
					$(this).attr('selected' , true);
					return false;
				} 
			}); 
		}
	});
	$(".check-all").click(function () {
		$(".ids").prop("checked", this.checked);
	});
	$(".ids").click(function () {
		var option = $(".ids");
		option.each(function (i) {
			if (!this.checked) {
				$(".check-all").prop("checked", false);
				return false;
			} else {
				$(".check-all").prop("checked", true);
			}
		});
	});
	$('button.check_ok').click(function(){
			var obj_self = $('input.ids:checked');
			if( obj_self.length <= 0 ) {
				error('请勾选需要操作的数据！');
				return false;	
			}
			if( $(this).attr('data-type') == 'ok' ) {
				var title = '确定要批量确认选择的订单？';
				var url = '{:U('Order/confirm')}';
			} else {
				var title = '确定要批量取消选择的订单？';
				var url = '{:U('Order/cancel')}';
			}
			var ids = '';
			obj_self.each( function(){
				ids += ',' + $(this).val();
			} );
			waitload('正在操作，请等待...');
			$.get( url , { id : ids.substr(1) } , function(data){
				zeroModal.closeAll();
				if( data.status == 1 ) {
					success( data.info , function(opt){ location.reload(); });	
				} else {
					error( data.info );	
				}
			}, 'json');
	});
</script>
</block>
